package com.mingqijia.gassafety.job.service.impl;

import com.alibaba.fastjson.JSONArray;
import com.gap.basic.base.CommonResponse;
import com.mingqijia.gassafety.job.response.AccountNumberListResp;
import com.mingqijia.gassafety.job.response.AccountNumberResp;
import com.mingqijia.gassafety.job.service.AccountNumberExportService;
import com.mingqijia.gassafety.shared.request.VccAccountNumberListRequest;
import com.mingqijia.gassafety.shared.utils.ApplicationUtils;
import com.mingqijia.gassafety.shared.vcc.VccSystemProvider;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @program: gassafety
 * @description: 账号管理实现
 * @author: zm
 * @create: 2024-07-30 13:43
 **/
@Service
@Slf4j
public class AccountNumberServiceImpl implements AccountNumberExportService {

    @Value(value = "${gassafety.ewt.url}")
    public String targetUrl;

    @Autowired
    private VccSystemProvider vccSystemProvider;

    @Override
    public List<AccountNumberResp> export(VccAccountNumberListRequest req) {
        String spId = ApplicationUtils.getWorkingSpId();
        String userId = ApplicationUtils.getUserId();
        CommonResponse<String> body = vccSystemProvider.account_number_list(req, spId, userId, targetUrl);
        log.info("账号列表返回结果：{}", body);
        if (body.getCode() != 0) return new ArrayList<>();
        AccountNumberListResp resp = JSONArray.parseObject(body.getData(), AccountNumberListResp.class);
        if (resp == null || resp.getDatas() == null) return new ArrayList<>();
        return resp.getDatas();
    }
}
